<template>
  <a-list item-layout="horizontal" :data-source="data">
    <template #renderItem="{ item }">
      <a-list-item>
        <a-list-item-meta>
          <template #description>
            <span>{{ item.description }}</span>
            <span v-if="item.value">：{{ item.value }}</span>
          </template>
          <template #title>
            <a>{{ item.title }}</a>
          </template>
        </a-list-item-meta>
        <template #actions>
          <router-link :to="{ name: item.routeName }"> 修改 </router-link>
        </template>
      </a-list-item>
    </template>
  </a-list>
</template>

<script lang="ts">
import { defineComponent, onMounted, reactive, toRefs } from 'vue'
import { getSecuritySetting } from '@/api/personal'

export default defineComponent({
  name: 'SecuritySettings',
  setup() {
    const state = reactive({
      data: [
        {
          title: '账户密码',
          description: '建议不定期修改密码',
          value: '',
          routeName: 'AccountPassword'
        },
        {
          title: '绑定手机',
          description: '已绑定手机',
          value: '',
          routeName: 'PhoneSettings'
        },
        {
          title: '绑定邮箱',
          description: '您还未绑定邮箱',
          value: '',
          routeName: ''
        }
      ]
    })
    onMounted(() => {
      getDataList()
    })
    function getDataList() {
      getSecuritySetting({}).then((res) => {
        if (res.phone) {
          state.data[1].value = res.phone
        }
        if (res.email) {
          state.data[2].value = res.email
          state.data[2].description = '已绑定邮箱'
        }
      })
    }
    return {
      ...toRefs(state)
    }
  }
})
</script>

<style lang="scss" scoped></style>
